package operation;

import book.BookList;
import ioperation.IOPeration;
import  book.Book;
import java.util.Scanner;

/**
 * @Description
 */

public class ReturnBook implements IOPeration {
    @Override
    public void work(BookList bookList) {
        System.out.println("归还图书....");
        System.out.println("请输入你要归还的图书：");
        Scanner scanner = new Scanner(System.in);
        String name = scanner.nextLine();

        //1.先遍历数组 查找是否存在要归还的图书
        int currentSize = bookList.getUsedSize();
        for (int i = 0; i < currentSize; i++) {
            Book book = bookList.getBook(i);
            if(book.getName().equals(name)) {
                if(!book.isBorrowed()) {
                    System.out.println("这本书没有被借出过，不用还！");
                }else {
                    System.out.println("归还成功");
                    book.setBorrowed(false);
                    System.out.println(book);
                }
                return;
            }
        }
        //4.如果不存在 则不能归还
        System.out.println("没有你要找的这本书，无法归还！！");
    }
}
